package com.zhida.common.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * Create by zhh 2024/7/15 19:23
 */
@Data
@NoArgsConstructor
public class Result <T> implements Serializable {
    private int code;
    private String msg;
    private T data;

    Result(int code,String msg,T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    Result(int code,String msg){
        this.code = code ;
        this.msg = msg;
    }

    Result(String msg){
        this.code = 200;
        this.msg = msg;
    }


    public static <T> Result<T> success(T data){
        return new Result<T>(200,"success",data);
    }

    public static Result<?> returnByInt(int result, String successMessage, String errorMessage){
        if (result > 0){
            return new Result<>(200, successMessage);
        }else {
            return new Result<>(500, errorMessage);
        }
    }

    public static <T> Result<T> error(String msg){
        return new Result<>(500,msg);
    }

    public static <T> Result<T> error403(String msg){
        return new Result<T>(403,msg);
    }

    public static <T> Result<T> successMsg(String msg) {
        return new Result<>(200,msg);
    }

    public static Result<?> error404(String msg) {
        return new Result<>(404 ,msg);
    }
}
